package com.crm.customers.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.crm.base.dao.BaseDao;
import com.crm.customers.dao.ContractDao;
import com.crm.customers.model.Contract;

@Repository("contractDao")
public class ContractDaoImpl extends BaseDao implements ContractDao {
	
	private static final String MAPPER_NAMESPACE = "ContractMapper.";
	
	@Override
	public List<Contract> getAllMyContractListByParams(Contract c) {
		List<Contract> list = selectList(MAPPER_NAMESPACE+"getAllMyContractListByParams", c);
		if (list!=null && list.size() > 0) {
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESPACE+"getAllMyContractListCountByParams", c));
		}
		return list;
	}

	@Override
	public Contract insert(Contract record) {
		insert(MAPPER_NAMESPACE+"insertSelective", record);
		return record;
	}

	@Override
	public int deleteByPrimaryKey(Long id) {
		 
		return 0;
	}

 
	@Override
	public Contract selectByPrimaryKey(Contract c) {
		return selectOne(MAPPER_NAMESPACE+"getContractInfoByParams", c);
	}

	@Override
	public int updateByPrimaryKeySelective(Contract record) {
		 
		return update(MAPPER_NAMESPACE+"updateByPrimaryKeySelective", record);
	}

	@Override
	public List<Contract> getAllContractListByPid(Contract c) {
		return selectList(MAPPER_NAMESPACE+"getAllContractListByPid", c);
	}

	@Override
	public Contract selecByCusid(Long cusid) {
		return selectOne(MAPPER_NAMESPACE+"selecByCusid", cusid);
	}

	@Override
	public int updateContractComplete(Contract c) {
		return update(MAPPER_NAMESPACE+"updateContractComplete", c);
	}

	@Override
	public Contract checkMoneyIsOver(Contract c) {
		return selectOne(MAPPER_NAMESPACE+"checkMoneyIsOver", c);
	}

	@Override
	public Integer getApprovemoney(Contract c) {
		Integer approvemoney = selectOne(MAPPER_NAMESPACE+"getApprovemoney", c);
		if (approvemoney == null) {
			return 0;
		} else {
			return approvemoney;
		}
	}

	@Override
	public List<Contract> getContractByPerformanceList(Contract c) {
		List<Contract> list = selectList(MAPPER_NAMESPACE+"getContractByPerformanceList", c);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((int)selectOne(MAPPER_NAMESPACE+"getContractByPerformanceListCount", c));
		}
		return list;
	}

	@Override
	public int getAllApprovemoney(Contract c) {
		Integer result = selectOne(MAPPER_NAMESPACE+"getAllApprovemoney", c);
		if (result == null) {
			return 0;
		} else {
			return result;
		}
	}

	@Override
	public List<Contract> getServiceManageList(Contract c) {
		List<Contract> list = selectList(MAPPER_NAMESPACE+"getServiceManageList", c);
		if (list != null && list.size() > 0) {
			list.get(0).setTotalResults((Integer)selectOne(MAPPER_NAMESPACE+"getServiceManageCount", c));
		}
		return list;
	}

	@Override
	public int checkResurmeHaveContract(Long cusid) {
		return selectOne(MAPPER_NAMESPACE+"checkResurmeHaveContract", cusid);
	}

	@Override
	public Contract getSonContractByParams(Contract c) {
		return selectOne(MAPPER_NAMESPACE+"getSonContractByParams", c);
	}

	@Override
	public int getSigningByDay(Contract c) {
		return selectOne(MAPPER_NAMESPACE+"getSigningByDay", c);
	}

}
